package net.thxjj.error;


public enum ErrCode implements ErrorCode{



	SUCCESS(200,"Success"),
	CMDID_CAN_NOT_EMPTY_ERROR(1400006,"Field cmdId not exist"),
	DATA_CAN_NOT_EMPTY_ERROR(1400007,"Data cannot be empty"),
	DEVTID_EMPTY_ERROR(1400008,"devTid can not be empty"),
	INSTRUCTION_NOT_EXIST_ERROR(1400011,"The device does not have this instruction"),
	ACTION_ERROR(1400016,"Action not support"),
	PARAMS_IS_NOT_EXIST_ERROR(1400017,"Params cannot be empty"),
	FIELD_INVALID_ERROR(1400032,"Field invalid"),

	UNKNOWN_DEVICE_ERROR(8400000,"Error"),
	JSON_FORMAT_ERROR(8400001,"Json parse error"),
	JWT_PARSE_ERROR(8400002,"JWT parse error"),
	BEYOND_UPPER_LIMIT_ERROR(8400003,"The field contains a value that is too high"),
	BEYOND_LOWER_LIMIT_ERROR(8400004,"The field contains a value that is too low"),
	PROPERTY_NOT_EXIST_ERROR(8400006,"Field not exist"),
	PRODUCTKEY_NOT_EXIST_ERROR(8400007,"Productkey not exist"),
	DEVTID_NOT_MATCH_ERROR(8400008,"devTid not match"),

	DEVICE_NOT_BELONG_TO_USER_ERROR(8400012,"Device does not belong to user"),
	PARAMETER_FORMAT_ERROR(8400013,"param format is invalid"),
	DEVICE_REPEAT_BIND_ERROR(8400014,"Device repeat bind"),
	DEVICE_TOKEN_ERROR(8400017,"Device token can not verification"),
	DEVICE_NOT_ONLINE(8400018,"Device is not online"),
	PRODUCT_KEY_NOT_AVAILABLE_ERROR(8400027,"Product key not available"),
	SSID_NOT_AVAILABLE_ERROR(8400028,"SSID not available"),
	BIND_FAiL_TIME_OUT_ERROR(8400029,"Bind failed due to timeout"),
	CAN_NOT_FORCE_BIND_ERROR(8400031,"Can not force bind device"),
	DEVICE_NOT_EXIST_ERROR(8400032,"Device is not exist"),
	CMD_NOT_EXIST_ERROR(8400034,"command id is not exist"),
	SERVER_INERNAL_ERROR(8500000,"Internal error"),


	  UNKNOWN_ERROR(9400000,"Unknow Error"),
	  CLIENT_NOT_EXIST_ERROR(8400010,"User does not exist"),
	  APP_REPEAT_LOGIN_ERROR(9400002,"App repeat login error"),
	  APPTID_EMPTY_ERROR(9400003,"appTid can not be empty"),
	  AUTHORIZATION_ALREADY_EXIST_ERROR(9400004,"Authorization already exists"),
	  AUTHORIZATION_NOT_EXIST_ERROR(9400005,"Authorization does not exist"),
	  MODIFY_CLIENT_PROFILE_FAILED_ERROR(9400009,"Modified user profile failed"),
	  CHECK_VERIFY_CODE_ERROR(9400010,"Check verify code error"),
	  REPEAT_BIND_ERROR(9400013,"Bind failed due to repeat bind"),
	  DEVICE_NOT_BELONG_CLIENT_ERROR(9400014,"Device does not belong to user"),
	  LOGIN_INFO_NOT_COMPLETE(9400018,"Login info not complete"),
	  PARAMETER_EMPTY_ERROR(9400019,"Parameter is empty"),
	  REFRESH_TOKEN_NOT_EXIST_ERROR(9400020,"refresh token not exist"),
	  REFRESH_TOKEN_TIME_OUT_ERROR(1,"refresh token time out"),
	  JWT_TIME_OUT_ERROR(403,"JWT time out"),
	  JWT_NOT_EXIST_ERROR(9400021,"JWT is not exist"),
	  JSON_PARSE_ERROR(9400022," Unable to parse Json,or Json is not in protocol"),
	  NUMBER_OUT_OF_RANGE(9400023, " Number out of range");




	/** 错误码 */
	private final int code;

	/** 描述 */
	private final String description;

	/**
	 * @param code 错误码
	 * @param description 描述
	 */
	private ErrCode(final int code, final String description) {
		this.code = code;
		this.description = description;
	}

	/**
	 * 根据编码查询枚举。
	 *
	 * @param code 编码。
	 * @return 枚举。
	 */
	public static ErrCode getByCode(int code) {
		for (ErrCode value : ErrCode.values()) {
			if (code == value.getCode()) {
				return value;
			}
		}
		return UNKNOWN_ERROR;
	}

	/**
	 * 枚举是否包含此code
	 * @param code 枚举code
	 * @return 结果
	 */
	public static Boolean contains(int code){
		for (ErrCode value : ErrCode.values()) {
			if (code == value.getCode()) {
				return true;
			}
		}
		return  false;
	}

	@Override
	public int getCode() {
		return code;
	}

	@Override
	public String getDescription() {
		return description;
	}
}
